package com.extremeforce.ansyc;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import org.xmlpull.v1.XmlPullParserException;

import android.content.Context;
import android.os.AsyncTask;
import android.widget.ListView;

import com.extremeforce.adapter.CouponListAdapter;
import com.extremeforce.client.IGuangClient;
import com.extremeforce.module.CouponActivity;
import com.extremeforce.parser.CouponParser;

public class GetCouponThread extends AsyncTask{
	
	private static final String NAMESPACE = "http://iface.extremeforce.com/";
	private static final String URL = IGuangClient.URL;
	
	
	private ArrayList<HashMap<String,Object>> list = new ArrayList<HashMap<String,Object>>();
	
	public GetCouponThread(ArrayList<HashMap<String,Object>> list){
		this.list = list;
	}
	
	@Override
	protected ArrayList<HashMap<String,String>> doInBackground(Object... arg0) {
		String METHOD_NAME = "getAllCoupons";
		String SOAP_ACTION =NAMESPACE + METHOD_NAME;
		SoapObject rpc = new SoapObject(NAMESPACE,METHOD_NAME);
		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
		envelope.bodyOut = rpc;
		envelope.dotNet = false;
		envelope.setOutputSoapObject(rpc);
		HttpTransportSE ht = new HttpTransportSE(URL);
		Object detail = null;
			try {
				
				ht.call(SOAP_ACTION,envelope);
				detail = envelope.getResponse();
				
			} catch (IOException e) {
				e.printStackTrace();
			} catch (XmlPullParserException e) {
				e.printStackTrace();
			}
		System.out.println(detail.toString());
		CouponParser couponParser = new CouponParser(list);
		couponParser.parse(detail.toString());
		
		return null;
	}

}
